package com.ds.dsfans.liteflow.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ds.dsfans.common.annotation.Log;
import com.ds.dsfans.common.enums.BusinessType;
import com.ds.dsfans.liteflow.domain.LiteflowScript;
import com.ds.dsfans.liteflow.service.ILiteflowScriptService;
import com.ds.dsfans.common.core.controller.BaseController;
import com.ds.dsfans.common.core.domain.AjaxResult;
import com.ds.dsfans.common.utils.poi.ExcelUtil;
import com.ds.dsfans.common.core.page.TableDataInfo;

/**
 * 规则引擎scriptController
 * 
 * @author dsfans
 * @date 2024-07-15
 */
@Controller
@RequestMapping("/liteflow/LiteflowScript")
public class LiteflowScriptController extends BaseController
{
    private String prefix = "liteflow/LiteflowScript";

    @Autowired
    private ILiteflowScriptService liteflowScriptService;

    @RequiresPermissions("liteflow:LiteflowScript:view")
    @GetMapping()
    public String LiteflowScript()
    {
        return prefix + "/LiteflowScript";
    }

    /**
     * 查询规则引擎script列表
     */
    @RequiresPermissions("liteflow:LiteflowScript:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LiteflowScript liteflowScript)
    {
        startPage();
        List<LiteflowScript> list = liteflowScriptService.selectLiteflowScriptList(liteflowScript);
        return getDataTable(list);
    }

    /**
     * 导出规则引擎script列表
     */
    @RequiresPermissions("liteflow:LiteflowScript:export")
    @Log(title = "规则引擎script", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LiteflowScript liteflowScript)
    {
        List<LiteflowScript> list = liteflowScriptService.selectLiteflowScriptList(liteflowScript);
        ExcelUtil<LiteflowScript> util = new ExcelUtil<LiteflowScript>(LiteflowScript.class);
        return util.exportExcel(list, "规则引擎script数据");
    }

    /**
     * 新增规则引擎script
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存规则引擎script
     */
    @RequiresPermissions("liteflow:LiteflowScript:add")
    @Log(title = "规则引擎script", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LiteflowScript liteflowScript)
    {
        return toAjax(liteflowScriptService.insertLiteflowScript(liteflowScript));
    }

    /**
     * 修改规则引擎script
     */
    @RequiresPermissions("liteflow:LiteflowScript:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LiteflowScript liteflowScript = liteflowScriptService.selectLiteflowScriptById(id);
        mmap.put("liteflowScript", liteflowScript);
        return prefix + "/edit";
    }

    /**
     * 修改保存规则引擎script
     */
    @RequiresPermissions("liteflow:LiteflowScript:edit")
    @Log(title = "规则引擎script", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LiteflowScript liteflowScript)
    {
        return toAjax(liteflowScriptService.updateLiteflowScript(liteflowScript));
    }

    /**
     * 删除规则引擎script
     */
    @RequiresPermissions("liteflow:LiteflowScript:remove")
    @Log(title = "规则引擎script", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(liteflowScriptService.deleteLiteflowScriptByIds(ids));
    }
}
